﻿using System.Web.Mvc;
using Beeldbankmvc.Models;

namespace Beeldbankmvc.Controllers
{
    public class PageTextController : Controller
    {
        PageTextRepository pageTextRepository = new PageTextRepository();

        //
        // GET: /PageText/

        public ActionResult Index()
        {
            var pageTextModels = pageTextRepository.getPageTextAll();

            return View(pageTextModels);
        }

        //
        // GET: /PageText/Details/5

        public ActionResult Details(int id)
        {
            var pageTextModel = pageTextRepository.FindOne(id);
            return View(pageTextModel);
        }

        //
        // GET: /PageText/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /PageText/Create

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                PageTextModel pageTextModel = new PageTextModel();

                // update the model with all the form fields contained in the FormCollection
                UpdateModel(pageTextModel);

                pageTextRepository.Create(pageTextModel);
                pageTextRepository.Save();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /PageText/Edit/5
 
        public ActionResult Edit(int id)
        {
            var pageTextModel = pageTextRepository.FindOne(id);
            return View(pageTextModel);
        }

        //
        // POST: /PageText/Edit/5

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                PageTextModel pageTextModel = new PageTextModel();

                // update the model with all the form fields contained in the FormCollection
                UpdateModel(pageTextModel);

                pageTextRepository.Update(pageTextModel);
                pageTextRepository.Save();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /PageText/Delete/5
 
        public ActionResult Delete(int id)
        {
            var pageTextModel = pageTextRepository.FindOne(id);
            return View(pageTextModel);
        }

        //
        // POST: /PageText/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                pageTextRepository.Delete(id);
                pageTextRepository.Save();
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
